package demo;

import utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author tongchen
 * @create 2022-12-27 14:02
 */
public class Update {
    //创建
    private static Connection connection;
    private static PreparedStatement statement;
    private static ResultSet resultSet;

    public static void main(String[] args) {
        //获取连接
        try {
           connection= DBUtils.getConnection();
           //定义sql语句
            String sql="update student set name=? where id =?";
            //创建执行器
            statement= connection.prepareStatement(sql);
            //不全sql
            statement.setString(1,"huahua");
            statement.setInt(2,12);
            //执行语句
            int i = statement.executeUpdate();
            if(i>0){
                System.out.println("执行成功");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
